home *** CD-ROM | disk | FTP | other *** search
/ Aminet 37 / Aminet 37 (2000)(Schatztruhe)[!][Jun 2000].iso / Aminet / dev / cross / devpic.lha / devpic / source / picrecv.c < prev    next >
C/C++ Source or Header  |  2000-04-24  |  3KB  |  134 lines

  1. #include <exec/memory.h>
  2. #include <clib/dos_protos.h>
  3. #include <clib/exec_protos.h>
  4. #include <clib/misc_protos.h>
  5. #include <clib/timer_protos.h>
  6. #include <pragmas/exec_sysbase_pragmas.h>
  7. #include <pragmas/timer_pragmas.h>
  8. #include <pragmas/misc_pragmas.h>
  9. #include <pragmas/dos_pragmas.h>
  10. #include <resources/misc.h>
  11. #include <dos/dos.h>
  12.  
  13. #define PORTVALUE *((STRPTR)0xbfe101)
  14. #define PORTSTATE *((STRPTR)0xbfe301)
  15. #define BSET(val,bit) val|=(1<<bit)
  16. #define BCLR(val,bit) val&=(~(1<<bit))
  17. #define BTST(val,bit) (val&(1<<bit))
  18.  
  19. struct Library *DOSBase, *SysBase, *MiscBase;
  20. static UBYTE pvout, psout;
  21. struct MsgPort *timereplyport;
  22. struct timerequest *timereq;
  23.  
  24. void pwait(void);
  25.  
  26. __saveds main()
  27. {
  28.     SysBase = *((struct Library **)4L);
  29.     if(DOSBase = OpenLibrary("dos.library",36))
  30.     {
  31.         if(MiscBase = OpenResource(MISCNAME))
  32.         {
  33.             if(timereplyport = CreateMsgPort())
  34.             {
  35.                 if(timereq = (struct timerequest *)CreateIORequest(timereplyport,sizeof(struct timerequest)))
  36.                 {
  37.                     if(!OpenDevice(TIMERNAME,UNIT_MICROHZ,(struct IORequest *)timereq,0))
  38.                     {
  39.                         STRPTR owner;
  40.                         if(!(owner = AllocMiscResource(MR_PARALLELPORT,"PIC debug info receiver")))
  41.                         {
  42.                             UBYTE fflag = 0;
  43.                             Printf("%s 1.5  © 2000 Russian Digital Computing\nCTRL/C - quit, CTRL/D - reset PIC\n","PIC debug info receiver");
  44.                             pvout = 1+2+8+16;
  45.                             PORTVALUE = pvout;
  46.                             psout = 2+4+8+16;
  47.                             PORTSTATE = psout;
  48.                             while(1)
  49.                             {
  50.                                 if(BTST(PORTVALUE,0))
  51.                                 {
  52.                                     if(fflag)
  53.                                     {
  54.                                         Flush(Output());
  55.                                         fflag = 0;
  56.                                     }
  57.                                     else
  58.                                     {
  59.                                         Delay(2);
  60.                                     }
  61.                                 }
  62.                                 else
  63.                                 {
  64.                                     UBYTE inbyte;
  65.                                     UBYTE cnt = 9;
  66.                                     while(cnt--)
  67.                                     {
  68.                                         inbyte <<= 1;
  69.                                         inbyte |= BTST(PORTVALUE,0);
  70.                                         BCLR(pvout,1);
  71.                                         pwait();
  72.                                         BSET(pvout,1);
  73.                                         pwait();
  74.                                     }
  75.                                     Printf("%02lx ",(ULONG)inbyte);
  76.                                     fflag = 1;
  77.                                 }
  78.                                 if(CheckSignal(SIGBREAKF_CTRL_C))
  79.                                 {
  80.                                     Printf("\n");
  81.                                     break;
  82.                                 }
  83.                                 if(CheckSignal(SIGBREAKF_CTRL_D))
  84.                                 {
  85.                                     BSET(pvout,2);
  86.                                     PORTVALUE = pvout;
  87.                                     BCLR(pvout,2);
  88.                                     PORTVALUE = pvout;
  89.                                 }
  90.                             }
  91.                             FreeMiscResource(MR_PARALLELPORT);
  92.                         }
  93.                         else
  94.                         {
  95.                             Printf("Can't allocate parallel port - it is owned by %s\n",owner);
  96.                         }
  97.                         CloseDevice((struct IORequest *)timereq);
  98.                     }
  99.                     else
  100.                     {
  101.                         Printf("Can't open %s\n",TIMERNAME);
  102.                     }
  103.                     DeleteIORequest((struct IORequest *)timereq);
  104.                 }
  105.                 else
  106.                 {
  107.                     Printf("Can't create IORequest\n");
  108.                 }
  109.                 DeleteMsgPort(timereplyport);
  110.             }
  111.             else
  112.             {
  113.                 Printf("Can't create msgport\n");
  114.             }
  115.         }
  116.         else
  117.         {
  118.             Printf("Can't open %s\n",MISCNAME);
  119.             return(0);
  120.         }
  121.         CloseLibrary(DOSBase);
  122.     }
  123.     return(0);
  124. }
  125.  
  126. void pwait()
  127. {
  128.     timereq->tr_node.io_Command = TR_ADDREQUEST;
  129.     timereq->tr_time.tv_secs = 0;
  130.     timereq->tr_time.tv_micro = 10;
  131.     DoIO((struct IORequest *)timereq);
  132.     PORTVALUE = pvout;
  133. }
  134.